package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.StoreRole;
import com.dingreading.cloud.admin.entity.table.StoreRoleTableDef;
import com.dingreading.cloud.admin.mapper.StoreRoleMapper;
import com.dingreading.cloud.admin.service.StoreRoleService;
import com.dingreading.cloud.common.util.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-02-26
 */
@Service
public class StoreRoleServiceImpl extends BaseServiceImpl<StoreRoleMapper, StoreRole, StoreRoleTableDef> implements StoreRoleService {

    @Override
    protected StoreRoleTableDef getTable() {
        return StoreRoleTableDef.storeRole;
    }

    @Override
    public Page<StoreRole> pageList(PageUtil pageUtil) {
        QueryCondition condition = QueryCondition.createEmpty();

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.id.asc());

        return getMapper().paginate(Page.of(pageUtil.getPage(), pageUtil.getRows()), wrapper);
    }

    @Override
    public int dropBean(Long roleId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.id.eq(roleId));

        return getMapper().deleteByCondition(condition);
    }

}
